package com.itheima.stream.listener;

import com.itheima.stream.config.DelaySink;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
public class MessageListener {


    //@StreamListener(Sink.INPUT) // 配置文件bindings:下的名字
/*    @StreamListener(MySink.INPUT) // 配置文件bindings:下的名字
    public void receive(Message<String> message) {
        System.out.println(message.getPayload());
        String name = message.getHeaders().get("name", String.class);
        System.out.println(name);
    }*/


/*    @StreamListener(MySink.INPUT) // 配置文件bindings:下的名字
    public void receive(@Payload String message,
                        @Header("name") String name,
                        @Header(AmqpHeaders.CONSUMER_TAG) String tag) {
        System.out.println(name);
        System.out.println(tag);
        System.out.println(message);
    }*/


/*
    @Autowired
    private Environment environment;


    @StreamListener(MySink.INPUT) // 配置文件bindings:下的名字
    public void receive(Map<String, String> message) {
        System.out.println("port="+environment.getProperty("server.port")
                +"msg="+message);
    }
*/



    @StreamListener(DelaySink.INPUT) // 配置文件bindings:下的名字
    public void receive(String message) {
        System.out.println(new Date());
        System.out.println(message);
    }
}
